﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UM_SERVER.Packet.InPacket;
using UM_SERVER.Packet.InPacket.UpdateUserInfo;
using UM_SERVER.Session;

namespace UM_SERVER.Packet
{
    class BasePacketListener : IPacketListener
    {
        #region IPacketListener 成员

        public bool Accpet(InPackage pck)
        {
            return pck.GetProtocol() == Protocol.NetworkProtocol.Base;
        }

        public void PackageArrived(InPackage pck)
        {
            //处理登陆包
            if (pck.Command == Protocol.IN_NetworkCommand.LOGIN_PACKAGE)
            {
                PackageProcess.Process_Login_Package(new LoginPacket(pck));
            }
            else
            {
                ISession session = Globle.sessionManager.GetSessionByCode(pck.GetSessionCode());
                //能够得到当前用户会话，并且该会话可用
                if (session != null && !session.GetExprid())
                {
                    switch (pck.Command)
                    {
                            //处理获取自身请求包
                        case Protocol.IN_NetworkCommand.GET_MYSELF_INFO_PACKAGE:
                            PackageProcess.Process_GetInfomation_Package(new GetMySelfInfoPacket(pck));
                            break;
                            //处理获取分组请求包
                        case Protocol.IN_NetworkCommand.GET_GROUP_PACKAGE:
                            PackageProcess.Process_Group_Package(new GetGroupPacket(pck));
                            break;
                            //处理获取指定分组中好友的请求包
                        case Protocol.IN_NetworkCommand.GET_FRIEND_BY_GROUP_PACKAGE:
                            PackageProcess.Process_GetFriendByGroup_Package(new GetFriendByGroupPacket(pck));
                            break;
                            //处理获取指定好友信息请求包
                        case Protocol.IN_NetworkCommand.GET_FRIEND_INFO_PACKAGE:
                            PackageProcess.Process_GetFriendInfo_Package(new GetFriendInfoPacket(pck));
                            break;
                            //处理修改个性签名请求包
                        case Protocol.IN_NetworkCommand.MODIFY_PROD_PACKAGE:
                            PackageProcess.Process_ModifyProd_Package(new ModifyProdPacket(pck));
                            break;
                            //处理更新用户挂起信息请求包
                        case Protocol.IN_NetworkCommand.UPDATE_USER_CHANAGE:
                            ///*******************************************************************
                            ///                             判断挂起信息类别
                            ///*******************************************************************
                            switch (pck.GetType())
                            {
                                    //更新昵称
                                case "UpdateChanageNickName":
                                    PackageProcess.Process_UpdateUserInfo(new UpdateUserNickNamePacket(pck));
                                    break;
                                    //更新个性签名
                                case "UpdateChanageProd":
                                    PackageProcess.Process_UpdateUserInfo(new UpdateUserProdPacket(pck));
                                    break;
                                    //更新姓名
                                case "UpdateChanageName":
                                    PackageProcess.Process_UpdateUserInfo(new UpdateUserNamePacket(pck));
                                    break;
                                    //更新性别
                                case "UpdateChanageSex":
                                    PackageProcess.Process_UpdateUserInfo(new UpdateUserSexPacket(pck));
                                    break;
                                    //更新电话
                                case "UpdateChanageTel":
                                    PackageProcess.Process_UpdateUserInfo(new UpdateUserTelPacket(pck));
                                    break;
                                    //更新电子邮箱
                                case "UpdateChanageEmal":
                                    PackageProcess.Process_UpdateUserInfo(new UpdateUserEmailPacket(pck));
                                    break;
                                    //更新密码
                                case "UpdateChanagePassword":
                                    PackageProcess.Process_UpdateUserInfo(new UpdateUserPasswordPacket(pck));
                                    break;
                                    //更新头像
                                case "UpdateChanageHeadImage":
                                    PackageProcess.Process_UpdateUserInfo(new UpdateUserHeadImagePacket(pck));
                                    break;
                            }
                            break;
                            //处理用户更新上线状态请求包
                        case Protocol.IN_NetworkCommand.CHANAGE_USER_ONLINE_STATE_PACKAGE:
                            PackageProcess.Process_ChanageUserOnlineState(new ChanageUserOnlineStatePacket(pck));
                            break;
                            //处理更新用户分组包
                        case Protocol.IN_NetworkCommand.UPDATE_ITEM_PACKAGE:
                            PackageProcess.Process_UpdateItem(new UpdateItemPacket(pck));
                            break;
                            //处理添加用户分组包
                        case Protocol.IN_NetworkCommand.ADD_NEW_ITEM_PACKAGE:
                            PackageProcess.Process_AddItem(new AddItemPacket(pck));
                            break;
                        //处理删除用户分组包
                        case Protocol.IN_NetworkCommand.DELETE_ITEM_PACKAGE:
                             PackageProcess.Process_DeleteItem(new DeleteItemPacket(pck));
                            break;
                        //处理获取要添加用户的信息请求包
                        case Protocol.IN_NetworkCommand.GET_POST_FRIEND_INFO_PACKAGE:
                            PackageProcess.Process_GetPostFriendInfo(new GetPostFriendInfoPacket(pck));
                            break;
                        //处理添加好友请求
                        case Protocol.IN_NetworkCommand.ADD_FRIEND:
                            PackageProcess.Process_AddFriend(new AddFriendPacket(pck));
                            break;
                        //处理添加好友结果包
                        case Protocol.IN_NetworkCommand.POST_ADD_FRIEND_RESULT_PAKCAGE:
                            PackageProcess.Process_PostAddFriendResult(new PostAddFriendResultPacket(pck));
                            break;
                        //处理删除好友请求包
                        case Protocol.IN_NetworkCommand.DELETE_FRIEND_PACKAGE:
                            PackageProcess.Process_DeleteFriend(new DeleteFriendPacket(pck));
                            break;
                        //处理用户心跳请求包
                        case Protocol.IN_NetworkCommand.HEART_BREATH_PACKAGE:
                            PackageProcess.Process_UserHeartBreath(new UserHeartBreathPacket(pck));
                            break;
                    }
                }
            }
        }

        #endregion
    }
}
